/* 左侧菜单栏 */



$(function(){
    let dropDown = $("#J_CategoryDropdown");
    $("#J_CategoryItems").children(".item").on("mouseenter", function (){
        $index = $(this).index();
        $(this).addClass("hover")
        $(this).children().children("a").hover(function(){
            $(this).css("color","red") 
        }
           
        );
        dropDown.css(
            "display","block"
        ).siblings().children(".category-all").css({
            "display": "none"
        });
        $(".category-all").eq($index).css(
            "display","block"
        );
        
    }).mouseleave(function () {
        $(this).removeClass("hover");
        dropDown.css({
            "display": "none"
        });
        $(".category-all").eq($index).css(
            "display","none"
        );
        $(this).children().children("a").css("color","") 
    });



/* 轮播 */

    let focus = $(".focus");
    let focusLists = $("#J_FocusSlider").children();
    let focusPages = $(".focus-pager").children();
    let focusControls = $(".focus-controls").children();
    let i=0;
    function move(){
        i++;
        if(i==focusLists.length){
            i=0;
        }
        if(i==-1){
            i=focusLists.length-1;
          }
    
        for(let j=0;j<focusLists.length;j++){
            focusLists[j].style.opacity = 0;
        }
        focusLists[i].style.opacity = 1;
        for(let j=0;j<focusPages.length;j++){
            focusPages[j].className = "";
          }
          focusPages[i].className='active';
    }
    let timer = setInterval(()=>{
        move();
    },3000)

    for(let j=0;j<focusPages.length;j++){
        focusPages[j].onmouseover = ()=>{
          i=j-1;
          move();
        }
      }

    focus.on("mouseenter",function(){
        focusControls.css("display","block");
    }).mouseleave(function(){
        focusControls.css("display","none");
    })
    focusControls[0].onclick = ()=>{
        i -=2;
        move();
      }
      focusControls[1].onclick = () =>{
        move();
      }


/* $.get("http://jx.xuzhixiang.top/ap/api/goods/goods-add.php",{
pimg:"../img/good-list01.jpg",
pname:"苹果iPhone13Pro(128G/全网通/5G版)",
price:7120,
}) */
$.get("http://jx.xuzhixiang.top/ap/api/allproductlist.php",{
        /* pagesize:1,
        pagenum:0, */
        uid:139213,
     }).then((resData)=>{
        localStorage.setItem("good-data",JSON.stringify(resData.data));
        // console.log(resData.data);
        let data = resData.data;
        let oUl = document.querySelector(".goods-list");
        let str="";

        data.forEach((item)=>{

            str +=`
            <li data-id="${item.pid}">
                  <a href target="_blank" class="pic"><img src="${item.pimg}" alt=""></a>
                  <h3><a href target="_blank">${item.pname}</a></h3>
                  <div class="price">最低价：<span>￥${item.pprice}</span></div>
                </li> 
            `
        })
        oUl.innerHTML = str;
        /* <li>
                  <a href="detail.html" target="_blank" class="pic"><img src="img/good-list01.jpg" alt=""></a>
                  <h3><a href="detail.html" target="_blank">苹果iPhone 13 Pro (128G/全网通/5G版)</a></h3>
                  <div class="price">最低价：<span>￥7120</span></div>
                </li> */
                 $(".goods-list li").on("click",function(){
                    let id = $(this).attr("data-id");
                    window.open(`detail.html?id=${id}`);
                    
                 });
                // console.log(lis);
                

     })


/*  */
     






    })
 
    
